﻿
using Assets.Scripts.Net.Data.Model;
using Assets.Scripts.Tool;
using Assets.Scripts.UI.Panel;
using UnityEngine.UI;
using UnityEngine;

namespace Assets.Scripts.UI.Item
{

    public class PaperGuideItem:UIBase<PaperGuideItem>
    {
        public Text QueNumText;//问题数字
        public Button GuideButton;//导航按钮
        public int QueId { get; set; }//用来搜索

        protected override UIType UIType
        {
            get { return UIType.Item;}
        }

        protected override void InitOnAwake()
        {
            AutoFindComponent(transform,true);
           
        }

        public void Init(int queIndex,int guideIndex, QueInfo info,bool isCheckScore)
        {
            GuideButton.onClick.AddListener(() => { OnGuideButtonClick(guideIndex); });
            QueId = info.id;
            QueNumText.text = queIndex.ToString();
            if (queIndex.Equals(55))
            {
                Debug.Log(info.isright);
            }
            if (isCheckScore)
            {
                // Debug.Log("info.isright:" + info.isright);
                if (info.isright == 1)
                {
                    //答对
                    SetGuideState(3);                    
                }
                else
                {
                    //答错
                    SetGuideState(4);
                }
            }
            else
            {
                SetGuideState(info.questate);
            }           
        }

        private void OnGuideButtonClick(int index)
        {
            ExamPanel._Instance.StartLocationByIndex(index);
        }

        /// <summary>
        /// 设置状态
        /// </summary>
        public void SetGuideState(int i)
        {
            switch (i)
            {
                case 0://未答
                    GuideButton.GetComponent<Image>().sprite= GuideButton.GetComponent<GuideSprite>().Sprites[0];
                    break;
                case 1://已答
                    GuideButton.GetComponent<Image>().sprite = GuideButton.GetComponent<GuideSprite>().Sprites[1];
                    break;
                case 2://疑问
                    GuideButton.GetComponent<Image>().sprite = GuideButton.GetComponent<GuideSprite>().Sprites[2];
                    break;
                case 3://答对
                    GuideButton.GetComponent<Image>().sprite = GuideButton.GetComponent<GuideSprite>().Sprites[1];
                    break;
                case 4://答错
                    GuideButton.GetComponent<Image>().sprite = GuideButton.GetComponent<GuideSprite>().Sprites[3];
                    break;
            }
        }
    }
}